package org.cainiao.basic.generics.wildcard;

import org.cainiao.basic.generics.wildcard.vo.Child;
import org.cainiao.basic.generics.wildcard.vo.Parent;

import java.util.Comparator;
import java.util.Optional;
import java.util.Random;
import java.util.function.Consumer;

/**
 * <br />
 * <p>
 * Author: Cai Niao(wdhlzd@163.com)<br />
 */
public class SuperTest {

    public static void main(String[] args) {
        testOptional();
        testComparator();
    }

    public static void testOptional() {
        int a = 1;
        int b = new Random(10).nextInt();
        Optional<Child> childOptional = Optional.ofNullable(a == b ? new Child() : null);
        Consumer<Parent> parentConsumer = (parent) -> System.out.println(parent.getName());
        childOptional.ifPresent(parentConsumer);
    }

    private static void testComparator() {
        Comparator<Child> childComparator = Comparator.comparingInt(Child::getSalary);
        Comparator<Parent> parentComparator = Comparator.comparing(Parent::getName);
        Comparator<Child> thenComparator = childComparator.thenComparing(parentComparator);

        Comparator<? super Child> parentComparator2 = childComparator;
    }

}
